From 274e01f431a68f4243b052e771bc3c1e5b72229c Mon Sep 17 00:00:00 2001 From: "gm281@boulderdash.cl.cam.ac.uk" Date: Sat, 14 Aug 2004 09:29:48 +0000 Subject: [PATCH] bitkeeper revision 1.1159.30.1 (411ddb8cj12XLuMNx_qS9SGeej51OQ) cpu_weight parameter added to the xm create command. Minor bug fix for BVT. --- tools/libxc/xc.h | 7 +++ tools/libxc/xc_domain.c | 63 +++++++++++++++++++++++++ tools/libxc/xc_linux_restore.c | 2 +- tools/python/xen/lowlevel/xc/xc.c | 11 +++-- tools/python/xen/xend/XendDomainInfo.py | 19 ++++---- tools/python/xen/xm/create.py | 7 ++- xen/common/sched_bvt.c | 2 +- 7 files changed, 96 insertions(+), 15 deletions(-) diff --git a/tools/libxc/xc.h b/tools/libxc/xc.h index b2cf0c67ba..046a00c268 100644 --- a/tools/libxc/xc.h +++ b/tools/libxc/xc.h @@ -48,6 +48,7 @@ int xc_domain_create(int xc_handle, unsigned int mem_kb, const char *name, int cpu, + float cpu_weight, u32 *pdomid); int xc_domain_pause(int xc_handle, u32 domid); @@ -62,6 +63,9 @@ int xc_domain_getinfo(int xc_handle, u32 first_domid, unsigned int max_doms, xc_dominfo_t *info); +int xc_domain_setcpuweight(int xc_handle, + u32 domid, + float weight); int xc_shadow_control(int xc_handle, u32 domid, @@ -209,6 +213,9 @@ typedef struct { int xc_physinfo(int xc_handle, xc_physinfo_t *info); +int xc_sched_id(int xc_handle, + int *sched_id); + int xc_domain_setname(int xc_handle, u32 domid, char *name); diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index 10017c74fe..6fab304f2e 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -12,6 +12,7 @@ int xc_domain_create(int xc_handle, unsigned int mem_kb, const char *name, int cpu, + float cpu_weight, u32 *pdomid) { int err; @@ -25,7 +26,11 @@ int xc_domain_create(int xc_handle, op.u.createdomain.cpu = cpu; if ( (err = do_dom0_op(xc_handle, &op)) == 0 ) + { *pdomid = (u16)op.u.createdomain.domain; + + err = xc_domain_setcpuweight(xc_handle, *pdomid, cpu_weight); + } return err; } @@ -171,6 +176,64 @@ int xc_domain_setname(int xc_handle, return do_dom0_op(xc_handle, &op); } +int xc_domain_setcpuweight(int xc_handle, + u32 domid, + float weight) +{ + int sched_id; + int ret; + + /* Figure out which scheduler is currently used: */ + if((ret = xc_sched_id(xc_handle, &sched_id))) + return ret; + + switch(sched_id) + { + case SCHED_BVT: + { + u32 mcuadv; + int warpback; + s32 warpvalue; + long long warpl; + long long warpu; + + /* Preserve all the scheduling parameters apart + of MCU advance. */ + if((ret = xc_bvtsched_domain_get(xc_handle, domid, &mcuadv, + &warpback, &warpvalue, &warpl, &warpu))) + return ret; + + /* The MCU advance is inverse of the weight. + Default value of the weight is 1, default mcuadv 10. + The scaling factor is therefore 10. */ + if(weight > 0) mcuadv = 10 / weight; + + ret = xc_bvtsched_domain_set(xc_handle, domid, mcuadv, + warpback, warpvalue, warpl, warpu); + break; + } + + case SCHED_FBVT: + { + // TODO + break; + } + case SCHED_RROBIN: + { + /* The weight cannot be set for RRobin */ + break; + } + case SCHED_ATROPOS: + { + /* TODO - can we set weights in Atropos? */ + break; + } + } + + return ret; +} + + int xc_domain_setinitialmem(int xc_handle, u32 domid, unsigned int initial_memkb) diff --git a/tools/libxc/xc_linux_restore.c b/tools/libxc/xc_linux_restore.c index 62050c83eb..4f4f2885c6 100644 --- a/tools/libxc/xc_linux_restore.c +++ b/tools/libxc/xc_linux_restore.c @@ -224,7 +224,7 @@ int xc_linux_restore(int xc_handle, XcIOContext *ioctxt) /* XXX create domain on CPU=-1 so that in future it auto load ballances by default */ if ( xc_domain_create( xc_handle, nr_pfns * (PAGE_SIZE / 1024), - name, -1, &dom ) ) + name, -1, 1, &dom ) ) { xcio_error(ioctxt, "Could not create domain. pfns=%d, %dKB", nr_pfns,nr_pfns * (PAGE_SIZE / 1024)); diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c index 4b5a426b55..840a954e94 100644 --- a/tools/python/xen/lowlevel/xc/xc.c +++ b/tools/python/xen/lowlevel/xc/xc.c @@ -44,16 +44,19 @@ static PyObject *pyxc_domain_create(PyObject *self, unsigned int mem_kb = 0; char *name = "(anon)"; int cpu = -1; + float cpu_weight = 1; u32 dom = 0; int ret; - static char *kwd_list[] = { "dom", "mem_kb", "name", "cpu", NULL }; + static char *kwd_list[] = { "dom", "mem_kb", "name", + "cpu", "cpu_weight", NULL }; - if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iisi", kwd_list, - &dom, &mem_kb, &name, &cpu) ) + if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iisif", kwd_list, + &dom, &mem_kb, &name, &cpu, &cpu_weight)) return NULL; - if ( (ret = xc_domain_create(xc->xc_handle, mem_kb, name, cpu, &dom)) < 0 ) + if ( (ret = xc_domain_create( + xc->xc_handle, mem_kb, name, cpu, cpu_weight, &dom)) < 0 ) return PyErr_SetFromErrno(xc_error); return PyInt_FromLong(dom); diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index 472cc0f74c..2c31d643c1 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -490,6 +490,7 @@ class XendDomainInfo: try: self.name = sxp.child_value(config, 'name') self.check_name(self.name) + self.cpu_weight = float(sxp.child_value(config, 'cpu_weight')) self.memory = int(sxp.child_value(config, 'memory')) if self.memory is None: raise VmError('missing memory size') @@ -709,8 +710,9 @@ class XendDomainInfo: memory = self.memory name = self.name cpu = int(sxp.child_value(self.config, 'cpu', '-1')) + cpu_weight = self.cpu_weight dom = self.dom or 0 - dom = xc.domain_create(dom= dom, mem_kb= memory * 1024, name= name, cpu= cpu) + dom = xc.domain_create(dom= dom, mem_kb= memory * 1024, name= name, cpu= cpu, cpu_weight= cpu_weight) if dom <= 0: raise VmError('Creating domain failed: name=%s memory=%d' % (name, memory)) @@ -1137,12 +1139,13 @@ add_device_handler('vbd', vm_dev_vbd) add_device_handler('pci', vm_dev_pci) # Ignore the fields we already handle. -add_config_handler('name', vm_field_ignore) -add_config_handler('memory', vm_field_ignore) -add_config_handler('cpu', vm_field_ignore) -add_config_handler('console', vm_field_ignore) -add_config_handler('image', vm_field_ignore) -add_config_handler('device', vm_field_ignore) -add_config_handler('backend', vm_field_ignore) +add_config_handler('name', vm_field_ignore) +add_config_handler('memory', vm_field_ignore) +add_config_handler('cpu', vm_field_ignore) +add_config_handler('cpu_weight', vm_field_ignore) +add_config_handler('console', vm_field_ignore) +add_config_handler('image', vm_field_ignore) +add_config_handler('device', vm_field_ignore) +add_config_handler('backend', vm_field_ignore) # Register other config handlers. diff --git a/tools/python/xen/xm/create.py b/tools/python/xen/xm/create.py index 69d6fb0b1f..4abbe1b91d 100644 --- a/tools/python/xen/xm/create.py +++ b/tools/python/xen/xm/create.py @@ -101,6 +101,10 @@ gopts.var('memory', val='MEMORY', fn=set_value, default=128, use="Domain memory in MB.") +gopts.var('cpu_weight', val='CPU_WEIGHT', + fn=set_value, default=1, + use="CPU weight.") + gopts.var('console', val='PORT', fn=set_int, default=None, use="Console port to use. Default is 9600 + domain id.") @@ -299,7 +303,8 @@ def make_config(vals): config = ['vm', ['name', vals.name ], - ['memory', vals.memory ] ] + ['memory', vals.memory ], + ['cpu_weight', vals.cpu_weight] ] if vals.cpu: config.append(['cpu', vals.cpu]) if vals.blkif: diff --git a/xen/common/sched_bvt.c b/xen/common/sched_bvt.c index e4ee214b54..c526f9fc9a 100644 --- a/xen/common/sched_bvt.c +++ b/xen/common/sched_bvt.c @@ -143,7 +143,7 @@ static inline u32 calc_avt(struct domain *d, s_time_t now) ranfor = (u32)(now - d->lastschd); mcus = (ranfor + MCU - 1)/MCU; - return inf->avt + mcus; + return inf->avt + mcus * inf->mcu_advance; } -- 2.30.2